package com.example.animatedemo;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;

public class MainActivity extends BaseSlideMenuActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
				WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
	
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_main);
		
		MenuFragment menuFrag = new MenuFragment();
		ContentFragment contentFrag = new ContentFragment();
		
		FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

		transaction.replace(R.id.menu_frame, menuFrag);
		
//		MySlideMenu.LayoutParams contentLayoutParams = new MySlideMenu.LayoutParams(
//				mSlideMenu.getContentView().getLayoutParams());
//		contentLayoutParams.setViewRole(MySlideMenu.VIEW_ROLE_CONTENT);
		transaction.replace(R.id.content_frame, contentFrag);
		
		transaction.commit();
		
		Button sideMenuBtn = (Button) findViewById(R.id.slide_side_menu);
		sideMenuBtn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Toast.makeText(getBaseContext(), "点击了侧边栏按钮", Toast.LENGTH_SHORT).show();
			
				Log.w("test", "show menu button clicked.");
				
				boolean isMenuShowing = sm.isMenuShowing();
				Log.w("test", "isMenuShow:" + isMenuShowing);
				
				if (isMenuShowing) {
					sm.showContent();
				} else {
					sm.showMenu();
				}
			}
		});
		
		ImageButton userIconBtn = (ImageButton) findViewById(R.id.slide_title_user_icon);
		userIconBtn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Toast.makeText(getBaseContext(), "点击了用户头像", Toast.LENGTH_SHORT).show();
			}
		});
		
		Button searchBtn = (Button) findViewById(R.id.slide_title_search);
		searchBtn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Toast.makeText(getBaseContext(), "点击了搜索按钮", Toast.LENGTH_SHORT).show();
			}
		});
		
		Log.e("test", "main activity on create end.");
	}
	
	public class MenuFragment extends Fragment {

		private Button mBtn;
		
		@Override
		public void onAttach(Activity activity) {
			// TODO Auto-generated method stub
			super.onAttach(activity);
		}
		
		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.menu_frag, null);
			
			mBtn = (Button) rootView.findViewById(R.id.menu_btn);
			mBtn.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					Log.w("test", "menu button clicked.");
					
					Toast.makeText(getActivity(), "点击了菜单按钮", Toast.LENGTH_SHORT).show();
				}
			});
			
			return rootView;
		}
	}
	
	public class ContentFragment extends Fragment {

		private Activity mContext;
		private Button mBtn;
		
		@Override
		public void onAttach(Activity activity) {
			// TODO Auto-generated method stub
			super.onAttach(activity);
			
			mContext = activity;
		}
		
		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.content_frag, null);
			
			mBtn = (Button) rootView.findViewById(R.id.content_btn);
			mBtn.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					Log.w("test", "content button clicked.");
					
					Toast.makeText(mContext, "点击了内容按钮", Toast.LENGTH_SHORT).show();
				}
			});
			
			return rootView;
		}
	}
}
